package cn.iocoder.yudao.module.erp.service.suppliersendorderitem;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.controller.admin.suppliersendorderitem.vo.SupplierSendOrderItemPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.suppliersendorderitem.vo.SupplierSendOrderItemSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.suppliersendorderitem.SupplierSendOrderItemDO;
import cn.iocoder.yudao.module.erp.dal.mysql.suppliersendorderitem.SupplierSendOrderItemMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.SUPPLIER_SEND_ORDER_ITEM_NOT_EXISTS;

/**
 * ERP 随货同行单项 Service 实现类
 * @author ls
 */
@Service
@Validated
public class SupplierSendOrderItemServiceImpl implements SupplierSendOrderItemService {

    @Resource
    private SupplierSendOrderItemMapper supplierSendOrderItemMapper;

    @Override
    public Long createSupplierSendOrderItem(SupplierSendOrderItemSaveReqVO createReqVO) {
        // 插入
        SupplierSendOrderItemDO supplierSendOrderItem = BeanUtils.toBean(createReqVO, SupplierSendOrderItemDO.class);
        supplierSendOrderItemMapper.insert(supplierSendOrderItem);
        // 返回
        return supplierSendOrderItem.getId();
    }

    @Override
    public void updateSupplierSendOrderItem(SupplierSendOrderItemSaveReqVO updateReqVO) {
        // 校验存在
        validateSupplierSendOrderItemExists(updateReqVO.getId());
        // 更新
        SupplierSendOrderItemDO updateObj = BeanUtils.toBean(updateReqVO, SupplierSendOrderItemDO.class);
        supplierSendOrderItemMapper.updateById(updateObj);
    }




    @Override
    public void deleteSupplierSendOrderItem(Long id) {
        // 校验存在
        validateSupplierSendOrderItemExists(id);
        // 删除
        supplierSendOrderItemMapper.deleteById(id);
    }

    private void validateSupplierSendOrderItemExists(Long id) {
        if (supplierSendOrderItemMapper.selectById(id) == null) {
            throw exception(SUPPLIER_SEND_ORDER_ITEM_NOT_EXISTS);
        }
    }

    @Override
    public SupplierSendOrderItemDO getSupplierSendOrderItem(Long id) {
        return supplierSendOrderItemMapper.selectById(id);
    }

    @Override
    public PageResult<SupplierSendOrderItemDO> getSupplierSendOrderItemPage(SupplierSendOrderItemPageReqVO pageReqVO) {
        return supplierSendOrderItemMapper.selectPage(pageReqVO);





    }

    @Override
    public void updateSupplierSendOrderItems(List<SupplierSendOrderItemSaveReqVO> updateReqVOList) {
        supplierSendOrderItemMapper.updateSupplierSendOrderItems(updateReqVOList);
    }

}